home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 11 / 011.d81 / pps #25 < prev    next >
Text File  |  2022-08-26  |  3KB  |  197 lines

  1.   PEEKs, POKEs, and SYSes -- Part 25
  2.  
  3.              "VARIABLES"
  4.  
  5.   Next we'll cover strings.  Strings
  6.  
  7. are relatively easy, but can get a bit
  8.  
  9. confusing.  Strings variables, just
  10.  
  11. like the other types, each use seven
  12.  
  13. bytes of variable space.  The first
  14.  
  15. two bytes represent the name.  The
  16.  
  17. high bit is set in only the second
  18.  
  19. byte of a string variable's name. The
  20.  
  21. third byte is the actual length of the
  22.  
  23. string.  The fourth and fifth bytes
  24.  
  25. are the pointer to the string.
  26.  
  27. (Remember our talk about envelopes?)
  28.  
  29. This pointer contains the address of
  30.  
  31. the actual contents of the string.
  32.  
  33. The string pointer is stored in the
  34.  
  35. usual format of low byte/high byte.
  36.  
  37. By looking at the address pointed to
  38.  
  39. to by the string pointer, you can get
  40.  
  41. a look at the actual string.
  42.  
  43. In the case of C$="TRY AGAIN.." it
  44.  
  45. would all look something like this:
  46.  
  47. The contents of the variable table:
  48.  067, 128, 011, 245, 159, 000, 000
  49.  < name > <len> <pointer> <unused>
  50.  
  51. So, CHR$(67) = "C", the name.
  52.  
  53. "TRY AGAIN.." is 11 characters long,
  54.  
  55. and found in memory at 40949 (245 +
  56.  
  57. 159*256 = 40949) like this:
  58.  
  59. The contents of the string, itself:
  60. 40949,50, 1, 2, 3, 4, 5, 6, 7, 8, 9
  61.    "T  R  Y     A  G  A  I  N  .  ."
  62. - - - - - - - - - - - - - - - - - - -
  63.  
  64.   Last but not least are the REALS.
  65.  
  66. They are the hardest to understand
  67.  
  68. because of the way in which they are
  69.  
  70. stored.  Real variables also take up
  71.  
  72. seven bytes of storage.  Again, the
  73.  
  74. first two represent the name.  Neither
  75.  
  76. byte has its high-bit set.  After that
  77.  
  78. is where the trouble starts.  Since
  79.  
  80. reals are floating-point numbers, they
  81.  
  82. are stored in floating-point form.
  83.  
  84. This means the 3rd byte is the
  85.  
  86. exponent and the next four bytes
  87.  
  88. represent the mantissa.  Since
  89.  
  90. floating-point notation is so darn
  91.  
  92. confusing (WE sure don't understand
  93.  
  94. it), we use a built-in ROM routine to
  95.  
  96. convert them to usable numbers (thank
  97.  
  98. goodness for ROM).  You can't really
  99.  
  100. use that routine at all as a BASIC
  101.  
  102. SYS.
  103. - - - - - - - - - - - - - - - - - - -
  104.  
  105.   The locations 47 and 48 point to the
  106.  
  107. beginning of array storage.  The start
  108.  
  109. of arrays "floats" on top of the
  110.  
  111. simple variable table.  This means
  112.  
  113. that the simple variables start at the
  114.  
  115. location pointed to by 45 and 46 and
  116.  
  117. end at the location pointed to by 47
  118.  
  119. and 48.
  120.  
  121.   Now that you're totally confused,
  122.  
  123. I'll tell you the good news.  To make
  124.  
  125. some use out of all this gobbledygook,
  126.  
  127. I have included a program on Side 2
  128.  
  129. of this disk.  It is a relatively
  130.  
  131. small machine-language routine which
  132.  
  133. prints the value(s) of all of your
  134.  
  135. simple BASIC variables.  (It doesn't
  136.  
  137. print any of the array variables.) I
  138.  
  139. have included the source file as well
  140.  
  141. for those of you who want to see just
  142.  
  143. how it is done.  It was coded using
  144.  
  145. BASM. The routine is saved under the
  146.  
  147. name of 'VARPRINT'.  The source file
  148.  
  149. is saved under the name of
  150.  
  151. 'VARPRINT.SRC'.
  152.  
  153.   To use the routine simply do the
  154.  
  155. following before you start any
  156.  
  157. programming:
  158.  
  159.  
  160.   1. LOAD"VARPRINT",8,1
  161.  
  162.   2. Type NEW
  163.  
  164.  
  165. Then you can go about doing whatever
  166.  
  167. you want, including writing and
  168.  
  169. running a BASIC program. Whenever you
  170.  
  171. want a list of all your variables,
  172.  
  173. simply type:
  174.  
  175.  
  176.   SYS 49664
  177.  
  178.  
  179. If you want the list sent to your
  180.  
  181. printer, try this:
  182.  
  183.   OPEN4,4,7
  184.   SYS 49664
  185.   PRINT#4
  186.   CLOSE4
  187.  
  188. This will send a list of all your
  189.  
  190. simple variables to the printer.
  191.  
  192.   I hope that this program will help
  193.  
  194. you in your programming efforts.
  195.  
  196. ----------<end of article>------------
  197.